<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/html5.js"></script>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/respond.min.js"></script>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="<?=base_url('publics/admin');?>/style/styles.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/lib/font-awesome/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="<?=base_url('publics/admin');?>/lib/font-awesome/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="<?=base_url('publics/admin');?>/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script type="text/javascript" src="<?php echo base_url('publics')?>/admin/editor/kindeditor.js"></script>     
<script type="text/javascript" src="<?php echo base_url('publics')?>/admin/editor/lang/zh_CN.js"></script>
<title>产品属性值</title>
</head>
<body>
<div id="main_right">
  <div id="r_title">
    <div id="r_title_content">
      产品管理 &gt; 增加产品属性值
    </div>
  </div>
  
  <div id="r_menu">
    <ul>
      <li><a class="btn btn-primary radius" href="<?=base_url('manage/product');?>">返回产品列表</a></li>
    </ul>
  </div>
    <div class="line_white"></div>
  <div id="r_list">
   <?php echo validation_errors(); ?>
    <form action="" method="post" class="form form-horizontal" id="" >
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>产品名：</label>
      <div class="formControls col-5">
        <?=$attr['pro_name'];?>
      </div>
      <div class="col-4"> </div>
    </div>    
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>产品属性名：</label>
      <div class="formControls col-5">
        <?=$attr['attr_name'];?>
      </div>
      <div class="col-4"> </div>
    </div>
    <?php if(!empty($value['val_id'])):?>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>属性默认值：</label>
      <div class="formControls col-5">
      <input type="text" size="30" name="value" id="value" placeholder=""  datatype="*0-20" class="input-text" nullmsg="名称不能为空" value="<?=$value['val_value'];?>" />
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>价格：</label>
      <div class="formControls col-5">
      <input type="text" size="30" name="price" id="price" placeholder=""  datatype="*0-20" class="input-text" nullmsg="名称不能为空" value="<?=$value['val_price'];?>"/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>描述：</label>
      <div class="formControls col-5">
        <textarea name="desc" id="desc" cols="" rows="" class="textarea"  placeholder="描述信息" datatype="*0-500" dragonfly="true" nullmsg="描述不能为空！" onKeyUp="textarealength(this,100)"><?=$value['val_desc'];?></textarea>
         <p class="textarea-numberbar"><em class="textarea-length">0</em>/500</p>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>是否默认选中：</label>
      <div class="formControls col-5 skin-minimal">
        <div class="radio-box">
          <input type="radio" id="sex-2" value="2" name="checked"  <?php if($value['val_checked'] == 2):?>checked="checked"<?php endif;?> >
          <label for="sex-2">其他</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-1" name="checked" value="1"  datatype="*" nullmsg="请选择状态"  <?php if($value['val_checked'] == 1):?>checked="checked"<?php endif;?> >
          <label for="sex-1">选中</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-2" value="0" name="checked"  <?php if($value['val_checked'] == 0):?>checked="checked"<?php endif;?> >
          <label for="sex-2">不选中</label>
        </div>
      </div>
      <div class="col-4"> </div>
    </div>

    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>排序：</label>
      <div class="formControls col-5">
        <input type="number" size="30" value="1" name="sort" id="sort" placeholder=""  datatype="*1-200" class="input-text" nullmsg="排序不能为空"/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>状态：</label>
      <div class="formControls col-5 skin-minimal">
        <div class="radio-box">
          <input type="radio" id="sex-1" name="status" value="1" checked="checked" datatype="*" nullmsg="请选择状态！">
          <label for="sex-1">有效</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-2" value="0" name="status">
          <label for="sex-2">无效</label>
        </div>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input class="btn btn-primary radius" type="botton" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="return check_from();">
      </div>
    </div>
    <input type="hidden" value="<?=$attr['pro_id'];?>" name="pro_id" id="pro_id">
    <input type="hidden" value="<?=$attr['attr_id'];?>" name="attr_id" id="attr_id">
     <?php else:?> 
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>属性默认值：</label>
      <div class="formControls col-5">
      <input type="text" size="30" name="value" id="value" placeholder=""  datatype="*0-20" class="input-text" nullmsg="名称不能为空" value="" />
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>价格：</label>
      <div class="formControls col-5">
      <input type="text" size="30" name="price" id="price" placeholder=""  datatype="*0-20" class="input-text" nullmsg="名称不能为空" value=""/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>描述：</label>
      <div class="formControls col-5">
        <textarea name="desc" id="desc" cols="" rows="" class="textarea"  placeholder="描述信息" datatype="*0-500" dragonfly="true" nullmsg="描述不能为空！" onKeyUp="textarealength(this,100)"></textarea>
         <p class="textarea-numberbar"><em class="textarea-length">0</em>/500</p>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>是否默认选中：</label>
      <div class="formControls col-5 skin-minimal">
        <div class="radio-box">
          <input type="radio" id="sex-2" value="2" name="checked" checked="checked">
          <label for="sex-2">其他</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-1" name="checked" value="1"  datatype="*" nullmsg="请选择状态！">
          <label for="sex-1">选中</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-2" value="0" name="checked">
          <label for="sex-2">不选中</label>
        </div>
      </div>
      <div class="col-4"> </div>
    </div>

    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>排序：</label>
      <div class="formControls col-5">
        <input type="number" size="30" value="1" name="sort" id="sort" placeholder=""  datatype="*1-200" class="input-text" nullmsg="排序不能为空"/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>状态：</label>
      <div class="formControls col-5 skin-minimal">
        <div class="radio-box">
          <input type="radio" id="sex-1" name="status" value="1" checked="checked" datatype="*" nullmsg="请选择状态！">
          <label for="sex-1">有效</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-2" value="0" name="status">
          <label for="sex-2">无效</label>
        </div>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input class="btn btn-primary radius" type="botton" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="return check_from();">
      </div>
    </div>
    <input type="hidden" value="<?=$attr['pro_id'];?>" name="pro_id" id="pro_id">
    <input type="hidden" value="<?=$attr['attr_id'];?>" name="attr_id" id="attr_id">
    <?php endif;?> 
  </form>
  </div>
   <?php if(isset($arr)):?>
   <div style="margin-top:50px;">
     <table class="table table-border table-bordered table-hover table-bg">
      <thead>
        <tr class="text-c">
          <th>属性值</th>
          <th width="300">简介</th>
           <th width="100">价格/元</th>
          <th width="100">是否选中</th>
          <th width="100">排序</th>
          <th width="100">状态</th>
          <th width="75">操作</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($arr as $val):?>
        <tr class="text-c">
          <td><input  size="2" class="input-text" type="text" value="<?=$val['val_value'];?>" id="val_value_<?=$val['val_id'];?>" onchange="update(<?=$val['val_id'];?>);"/></td>
          <td>          
              <input  size="2" class="input-text" type="text" value="<?=$val['val_desc'];?>" id="val_desc_<?=$val['val_id'];?>" onchange="update(<?=$val['val_id'];?>);"/>
          </td>
          <td>          
              <input  size="2" class="input-text" type="text" value="<?=$val['val_price'];?>" id="val_price_<?=$val['val_id'];?>"  onchange="update(<?=$val['val_id'];?>);"/>
          </td>
          <td>
             <select name="checked" onchange="update(<?=$val['val_id'];?>);" id="val_checked_<?=$val['val_id'];?>">
                <option value="0" <?php if($val['val_checked'] == 0):?>selected<?php endif;?>>不选中</option>
                <option value="1" <?php if($val['val_checked'] == 1):?>selected<?php endif;?>>选中</option>
                <option value="2" <?php if($val['val_checked'] == 2):?>selected<?php endif;?>>其它</option>
              </select>
          </td>
          <td>
              <input type="number" size="30"  name="sort" placeholder=""  datatype="*1-200" class="input-text" nullmsg="排序不能为空" id="val_sort_<?=$val['val_id'];?>" value="<?=$val['val_sort'];?>" onchange="update(<?=$val['val_id'];?>);" />
          </td>
          <td>
             <select name="status" onchange="update(<?=$val['val_id'];?>);" id="val_status_<?=$val['val_id'];?>">
                <option value="1" <?php if($val['val_status'] == 1):?>selected<?php endif;?>>有效</option>
                <option value="0" <?php if($val['val_status'] == 0):?>selected<?php endif;?>>无效</option>
              </select>
          </td>
          <td>
            <a title="删除" href="javascript:;"  onclick="return deldata(<?=$val['val_id'];?>);" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a>
          </td>
        </tr>
        <?php endforeach;?>
    
      </tbody>
    </table>
  </div>
  <?php endif;?>
</div>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/jquery.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/layer1.8/layer.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/Validform_v5.3.2.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/js/H-ui.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/js/H-ui.admin.js"></script> 
<script type="text/javascript">
$(function(){
	$("#form-menu-add").Validform({
		tiptype:2,
	});
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});

  var editor;
  KindEditor.ready(function(K) {
          editor = K.create('#content');
  });
});

function check_from(){
  var valData = {
      'attr_id'     :  $('#attr_id').val(),
      'val_value'   :  $('#value').val(),
      'val_price'   :  $('#price').val(),
      'val_desc'    :  $('#city').val(),
      'val_checked' :  $('input[name="checked"]:checked').val(),
      'val_sort'    :  $('#sort').val(),
      'val_status'  :  $('input[name="status"]:checked').val()
  }
  
  $.ajax({
        type : 'POST',
        url  : '<?=base_url('manage/value/add');?>',
        data : valData,
        success:function(msg){
          if(msg == 'ok'){
            alert('增加成功!');
            location.href = '/manage/value/insert?pid='+<?php echo $attr['pro_id'];?>+'&aid='+<?php echo $attr['attr_id'];?>;
          }
          
        }
  });
}

function deldata(id){
  $.layer({
      shade: [0],
      area: ['auto','auto'],
      dialog: {
          msg: '确定要删除该属性值吗？',
          btns: 2,                    
          type: 4,
          btn: ['是','否'],
          yes: function(){
          $.get("/manage/value/value_delete?id="+id,function(res){
              if(res == 'ok'){
                layer.msg('删除成功!', 1, 1);
                location.reload();
              }else{
                layer.msg('删除失败!', 1, 3);
              }
          });
          }, no: function(){}
      }
  });
}

function update(id){
  var valData = {
      'val_value'   :  $('#val_value_'+id).val(),
      'val_price'   :  $('#val_price_'+id).val(),
      'val_desc'    :  $('#val_desc_'+id).val(),
      'val_checked' :  $('#val_checked_'+id).val(),
      'val_sort'    :  $('#val_sort_'+id).val(),
      'val_status'  :  $('#val_status_'+id).val()
  }
  $.ajax({
      type : 'POST',
      url  : '<?=base_url('manage/value/update_value');?>?id='+id,
      data : valData,
      success:function(msg){
        if(msg == 'ok'){
           location.href = '';
        }else{
           layer.msg('修改失败,请联系网站管理员,');
        }       
      }
  });

}
</script> 
</body>
</html>